package com.shipwe.loans.pro

import com.shipwe.loans.MyApps
import com.shipwe.loans.base.BaseFragment
import com.shipwe.loans.http.IHttpCallback
import com.shipwe.loans.utils.event.AppEventData
import com.shipwe.loans.utils.event.AppEventPointHelper
import com.shipwe.loans.utils.event.AppEventSubscriber
import org.json.JSONObject

/**
 * Shipwe
 * @Author wwdeng
 * @CreateTime: 2024/11/28 10:32
 * @Annotation：
 */
abstract class ShipweFragment: BaseFragment(), AppEventSubscriber,IShipweView {

    override fun getAct(): ShipweActivity {
        return context as ShipweActivity
    }

    /**
     * 客服
     */
    fun showCustomerDialog(eventRemark: String = "",pName: String = "", pToken: String = ""){
        getAct().showCustomerDialog(eventRemark,pName,pToken)
    }

    override fun onStart() {
        super.onStart()
        MyApps.app.publisher.register(this)
    }

    /**
     * 错误提示
     */
    fun showErrorTipsDialog(tips: String,eventRemark: String = ""){
        getAct().showErrorTipsDialog(tips,eventRemark)
    }

    /**
     * post
     */
    fun doPostAction(httpUrl: String, params: JSONObject, callback: IHttpCallback){
        getAct().doPostAction(httpUrl, params, callback)
    }

    /**
     * 添加埋点
     */
    fun appEventPointRequestAction(eventName: String, eventRemark: String = "") {
        AppEventPointHelper.appEventPointRequestAction(eventName,eventRemark)
    }

    /**
     * 发送事件通知
     */
    fun publishEventData(eventData: AppEventData){
        MyApps.app.publisher.publish(eventData)
    }

    /**
     * 处理订阅事件
     */
    override fun onShipwePublishEvent(event: AppEventData) {

    }

    override fun onDestroy() {
        super.onDestroy()
        MyApps.app.publisher.detach(this)
    }
}